class Photo < ActiveRecord::Base
  
  belongs_to :album, :dependent => :nullify
  
  acts_as_list :scope => :album_id
  
  has_attachment :content_type => :image, 
    :storage => :file_system, 
    :max_size => 3.megabytes,
    :thumbnails => { :small => '500x500>',
                   :thumb => [100, 100] }
  
  validates_as_attachment
  
  def full_filename(thumbnail = nil)
    file_system_path = (thumbnail ? thumbnail_class : self).attachment_options[:path_prefix].to_s

    if album.nil?
      album_string = parent.album.to_param
    else
      album_string = album.to_param
    end
    
    photo_string = parent_id || id
    File.join(RAILS_ROOT, file_system_path, album_string, photo_string.to_s, thumbnail_name_for(thumbnail))
  end
  
  def to_s
    filename
  end
end
